package com.dingreading.cloud.mall.controller;

import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.mall.service.ShopCartV5Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/front/shopCart")
@Api(tags = "商城-购物车管理")
public class FrontShopCartControllerV5 {

    @Resource
    protected ShopCartV5Service shopCartV5Service;


    @ApiOperation(value = "我的购物车列表")
    @PostMapping(value = "/myShopCarts", produces = "application/json; charset=UTF-8")
    public R<Object> myShopCarts(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName
    ) {
        return shopCartV5Service.myShopCarts(storeUid, staffUid);
    }


    @ApiOperation(value = "修改数量")
    @PostMapping(value = "/editNum", produces = "application/json; charset=UTF-8")
    public R<Object> editNum(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "id") @RequestParam(value = "id") Long id,
            @ApiParam(value = "数量") @RequestParam(value = "num", required = false) Integer num,
            @ApiParam(value = "类型 1.加 0.减") @RequestParam(value = "type", required = false) Integer type
    ) {
        return shopCartV5Service.editNum(storeUid, staffUid, staffName, id, num, type);
    }


    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete", produces = "application/json; charset=UTF-8")
    public R<Object> delete(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "id集合") @RequestParam(value = "ids") List<Long> ids
    ) {
        return shopCartV5Service.deleteByIdIn(storeUid, staffUid, ids);
    }


    @ApiOperation(value = "商品加入购物车")
    @PostMapping(value = "/addToShopCart", produces = "application/json; charset=UTF-8")
    public R<Object> addToShopCart(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @RequestParam(value = "goodsId") @ApiParam(value = "商品id") Long goodsId,
            @RequestParam(value = "goodsTypeId") @ApiParam(value = "商品规格id") Long goodsTypeId,
            @RequestParam(value = "num") @ApiParam(value = "数量") Integer num
    ) {
        return shopCartV5Service.addToShopCart(storeUid, staffUid, staffName, goodsId, goodsTypeId, num);
    }


    @ApiOperation(value = "获取购物车记录详情")
    @ApiImplicitParam(name = "shopCartIds", value = "shopCartIds", allowMultiple = true, dataTypeClass = List.class, paramType = "query")
    @PostMapping(value = "/getShopCartInfo", produces = "application/json; charset=UTF-8")
    public R<Object> getShopCartInfo(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "员工代金券id") @RequestParam(value = "couponStaffId", required = false) Long couponStaffId,
            @RequestParam(value = "shopCartIds") @ApiParam(value = "购物车id集合") List<Long> shopCartIds
    ) {
        return shopCartV5Service.getShopCartInfo(storeUid, staffUid, couponStaffId, shopCartIds);
    }

    @ApiOperation(value = "立即购买")
    @PostMapping(value = "/nowNewShopCart", produces = "application/json; charset=UTF-8")
    public R<Object> nowNewShopCart(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @RequestParam(value = "goodsId") @ApiParam(value = "商品id") Long goodsId,
            @RequestParam(value = "goodsTypeId") @ApiParam(value = "商品规格id") Long goodsTypeId,
            @RequestParam(value = "num") @ApiParam(value = "数量") Integer num,
            @RequestParam(value = "remark", required = false) @ApiParam(value = "备注") String remark
    ) {
        return shopCartV5Service.nowNewShopCart(storeUid, staffUid,staffName, goodsId, goodsTypeId, num, remark);
    }


    @ApiOperation(value = "获取购物车记录详情的可用代金券和收货地址")
    @PostMapping(value = "/getCouponAndDeliveryAddress", produces = "application/json; charset=UTF-8")
    public R<Object> getCouponAndDeliveryAddress(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @RequestParam(value = "shopCartIds") @ApiParam(value = "购物车id集合") List<Long> shopCartIds
    ) {
        return shopCartV5Service.getCouponAndDeliveryAddress(storeUid,staffUid, shopCartIds);
    }


    @ApiOperation(value = "购物车新建订单")
    @PostMapping(value = "/newOrder", produces = "application/json; charset=UTF-8")
    public R<Object> newOrder(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "购物车id集合") @RequestParam(value = "shopCartIds") List<Long> shopCartIds,
            @ApiParam(value = "送货地址id") @RequestParam(value = "deliveryId") Long deliveryId,
            @ApiParam(value = "员工代金券id") @RequestParam(value = "couponStaffId", required = false) Long couponStaffId,
            @ApiParam(value = "备注") @RequestParam(value = "remark", required = false) String remark
    ) throws Exception {
        return shopCartV5Service.newOrder(corpUid, storeUid,storeName, staffUid, staffName ,shopCartIds, deliveryId, couponStaffId, remark);
    }


    @ApiOperation(value = "获取我的购物车数量")
    @PostMapping(value = "/getShopCartNum", produces = "application/json; charset=UTF-8")
    public R<Object> getShopCartNum(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName
    ) {
        long count = shopCartV5Service.getStaffShopCartCountV3(storeUid, staffUid);
        return R.ok(count);
    }

}